#! /bin/sh -f
:
: '		    Shell script to install the Mainframed server.                 '
:
: 'Written by Charles L. Perkins, July 25th, 1990.     Last modified:  7/25/90'

ODpath=$HOME/#Conextions/3270Vision2.0
rc=/etc/rc.local
rcBackup=$rc.BACKUP
serverDir=/LocalApps
serverName=Mainframed
serverPath=$serverDir/$serverName.app/$serverName
# since it is an app, it is in /LocalApps/Mainframed/Mainframed

echo "Beginning installation of the $serverName server..."
echo ""

if [ "`whoami`" != root ]
then
	echo "	You are not super-user (root)!"; echo ""
	echo "You should login as root and try again."
	echo "Terminating installation procedure for now."
		exit 1
fi

xxx=`grep -c Mainframed /etc/rc.local`
if [ .$xxx = .2 ] 
then
	echo "/etc/rc.local already has Mainframed installed"
else
	if [ -f $rc ]
	then
		echo "done."
		echo -n "Moving $rc to $rcBackup...."
		mv $rc $rcBackup   &&   echo "done."
		echo -n "Copying $rcBackup to $rc...."
		cp $rcBackup $rc   &&   echo "done."
		echo "Editing $rc to automatically start $serverPath"
		ed $rc <<!
/local daemons/a
if [ -f $serverPath ]; then
	$serverPath & (echo -n " $serverName")	>/dev/console 2>&1
fi
.
w
q
!
		echo "...done."
		echo ""
		echo "Now all you need to do is reboot your NeXT machine."
		echo ""
		echo -n "I can do this for you, do you want me to (y or n)? "
		read answer
		case $answer in
			y|Y|yes|YES|Yes)
				/usr/etc/reboot;;
		esac
		echo "The installation procedure is now complete."
	else
		echo "No $rc file!  I must terminate the installation."
		exit 1
	fi
fi

echo ""
echo "Press RETURN when you're done reading the above output."
read answer
